{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "774a1152",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-11\n",
    "* 课程：python语言\n",
    "* week04（上课周）\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b69acb1f",
   "metadata": {},
   "source": [
    "# 1.本周内容\n",
    "\n",
    "## 1、数值\n",
    "\n",
    "## 2、字符串\n",
    "\n",
    "## 3、range()函数\n",
    "\n",
    "## 4、for循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40bf9124",
   "metadata": {},
   "source": [
    "# 2、数值\n",
    "\n",
    "> 1. [数值的概念--教程](https://docs.python.org/zh-cn/3/tutorial/index.html)\n",
    "> 2. [数值的总结--分类](https://docs.python.org/3/library/index.html)\n",
    "> 2. 数值的分类\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "7f918b16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 + 2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4c906381",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "50 - 5*6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ca0a1b2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8/5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "f3660831",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 // 3  #取整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e23bd67a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 % 3  #取余"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6e5e2213",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值的方法\n",
    "abs(-8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8d2e05ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值类型\n",
    "\n",
    "a = 2023\n",
    "type(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b9fbbff",
   "metadata": {},
   "source": [
    "# 3.字符串\n",
    "\n",
    "> 1. 字符串的概念与形态\n",
    "> 2. 字符串的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "c42d357a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1975'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " \"1975\"\n",
    "    # 笔记：如果引号里面是数值，其结果仍为字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "abf5d4be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(\"1975\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "94ed4552",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的重要特征：序列\n",
    "\n",
    "地址 = \"广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2ec72f6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "fb94dfdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0] #取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "6d3c371f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南方学'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[2:5] #切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "6a1315f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址.count(\"广州\") #查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ee3a9d67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "70585a29",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学院'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-2:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8f5b30b",
   "metadata": {},
   "source": [
    "# 4.佛如循环和range()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "518c04c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广,\n",
      "州,\n",
      "南,\n",
      "方,\n",
      "学,\n",
      "院,\n"
     ]
    }
   ],
   "source": [
    "# 把如下的操作称为：循环遍历\n",
    "for item in 地址:\n",
    "    print(item + \",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db01ae4b",
   "metadata": {},
   "source": [
    "* range()可以确定范围，并且决定for循环的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "fa96583d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "bae90224",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(10,20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b3069e2",
   "metadata": {},
   "source": [
    "## for循环实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af1171db",
   "metadata": {},
   "source": [
    "### 实践一：创建学号\n",
    "### 增加条件判断，优化学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "53b625ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023010301\n",
      "2023010302\n",
      "2023010303\n",
      "2023010304\n",
      "2023010305\n",
      "2023010306\n",
      "2023010307\n",
      "2023010308\n",
      "2023010309\n",
      "2023010310\n",
      "2023010311\n",
      "2023010312\n",
      "2023010313\n",
      "2023010314\n",
      "2023010315\n",
      "2023010316\n",
      "2023010317\n",
      "2023010318\n",
      "2023010319\n",
      "2023010320\n",
      "2023010321\n",
      "2023010322\n",
      "2023010323\n",
      "2023010324\n",
      "2023010325\n",
      "2023010326\n",
      "2023010327\n",
      "2023010328\n",
      "2023010329\n",
      "2023010330\n",
      "2023010331\n",
      "2023010332\n",
      "2023010333\n",
      "2023010334\n",
      "2023010335\n",
      "2023010336\n",
      "2023010337\n",
      "2023010338\n",
      "2023010339\n",
      "2023010340\n",
      "2023010341\n",
      "2023010342\n",
      "2023010343\n",
      "2023010344\n",
      "2023010345\n",
      "2023010346\n",
      "2023010347\n",
      "2023010348\n",
      "2023010349\n",
      "2023010350\n",
      "2023010351\n",
      "2023010352\n",
      "2023010353\n",
      "2023010354\n",
      "2023010355\n",
      "2023010356\n",
      "2023010357\n",
      "2023010358\n",
      "2023010359\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,60):\n",
    "    # print(i)\n",
    "    if i > 9:\n",
    "        print(\"20230103\" + str(i))\n",
    "    else:\n",
    "         print(\"202301030\" + str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21152d35",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
